package cz.muni.fi.pb138.accountingRecords;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * Class representing subject of trade (physical item or service),
 * default getters and setters, except of constraints for precision of BigDecimal
 * @author Michal
 */
public class Item {

    private String note;//name of item or service
    private BigDecimal priceForUnit;
    private Integer count;

    /**
     * Returns amount of items that were sold
     * @return
     */
    public Integer getCount() {
        return count;
    }

    /**
     * Sets amount of items that were sold
     * @param count amount of items that were sold
     */
    public void setCount(Integer count) {
        this.count = count;
    }

    /**
     * returns name of item that was sold
     * @return name of item that was sold
     */
    public String getNote() {
        return note;
    }

    /**
     * sets name of item that was sold
     * @param name name of item that was sold
     */
    public void setNote(String name) {
        this.note = name;
    }

    /**
     * returns price for one unit of item
     * @return price for one unit of item
     */
    public BigDecimal getPriceForUnit() {
        return priceForUnit.setScale(2,RoundingMode.HALF_UP);
    }

    /**
     * returns price for one unit of item
     * @param priceForUnit price for one unit of item
     */
    public void setPriceForUnit(BigDecimal priceForUnit) {
        this.priceForUnit = priceForUnit.setScale(2,RoundingMode.HALF_UP);
    }

    /**
     * Compares two items by name and price for unit
     * @param obj item that will be compared
     * @return true if two items have same name and price for unit, false otherwise
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Item other = (Item) obj;
        if ((this.note == null) ? (other.note != null) : !this.note.equals(other.note)) {
            return false;
        }
        if (this.priceForUnit != other.priceForUnit && (this.priceForUnit == null || !this.priceForUnit.equals(other.priceForUnit))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + (this.note != null ? this.note.hashCode() : 0);
        hash = 79 * hash + (this.priceForUnit != null ? this.priceForUnit.hashCode() : 0);
        return hash;
    }
    
}
